package com.itheima.controller;

import com.itheima.common.CheckDto;
import com.itheima.common.ChoiceDto;
import com.itheima.common.PageResult;
import com.itheima.pojo.hm.HmQuestions;
import com.itheima.service.HmQuestionsAuditsService;
import com.itheima.service.QuestionsRecordsService;
import com.itheima.service.QuestionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/questions")
public class QuestionController {
    @Autowired
    private HmQuestionsAuditsService hmQuestionsAuditsService;
    @Autowired
    private QuestionsRecordsService questionsRecordsService;
    @Autowired
    private QuestionsService questionsService;

    //审核意见
    @GetMapping("/{id}/auditOpinions")
    public Object[] auditOpinions(@PathVariable Integer id){
        return hmQuestionsAuditsService.auditOpinions(id);
    }

    //出题记录
    @GetMapping("/{id}/setRecords")
    protected Object[] setRecords(@PathVariable Integer id){
        return questionsRecordsService.setRecords(id);
    }

    //基础题库列表
    @GetMapping
    public PageResult list(Long page,Long pagesize,Integer subjectID,String question){
        PageResult result =questionsService.findList(page,pagesize,subjectID,question);
        return result;
    }

    //基础题库添加
    @PostMapping
    public void addQusetion(@RequestBody HmQuestions hmQuestion){
        questionsService.add(hmQuestion);
    }

    //基础题库删除
    @DeleteMapping("/{id}")
    public void removeById(@PathVariable Integer id){
        questionsService.removeById(id);
    }

    //基础数据
    @GetMapping("/{id}")
    public  HmQuestions findQuestion(@PathVariable  Integer id){
        return questionsService.findQuestion(id);
    }

    //修改数据
    @PutMapping("/{id}")
    public void modify(@RequestBody HmQuestions hmQuestions) {
        questionsService.modifyById(hmQuestions);
    }

    //加入或移除精选
    @PatchMapping("/choice/{id}/{choiceState}")
    public void modifyChoiceState(@RequestBody ChoiceDto choiceDto) {
        questionsService.modifyChoiceState(choiceDto);
    }

    //精选题库列表
    @GetMapping("/choice")
    public PageResult Choice(Long page, Long pagesize) {
        PageResult result = questionsService.choice(page, pagesize);
        return result;
    }

    //审核
    @PostMapping("/check/{id}")
    public void CheckQuestion(@RequestBody CheckDto checkDto) {
        questionsService.checkQuestion(checkDto);
    }
    //上下架
    @PostMapping("/choice/{id}/{publishState}")
    public void  modifyPublishState(@PathVariable Integer id,@PathVariable Integer publishState){
        questionsService.modifyPublishState(id,publishState);
    }
}
